package com.ithuangyl.common.web.event;

import java.util.HashMap;

/**
 * author : itHuang
 * e-mail : ithuangyl@163.com
 * date   : 2020/6/23 10:41
 */
public class EventManager {
    private static final HashMap<String, Event> EVENTS = new HashMap<>();

    private EventManager() {
    }

    private static class Holder {
        private static final EventManager INSTANCE = new EventManager();
    }

    public static EventManager getInstance() {
        return Holder.INSTANCE;
    }

    public  void addEvent(String action, Event event) {
        EVENTS.put(action, event);
    }

    public  Event getEvent(String action) {
        final Event event = EVENTS.get(action);
        if (event == null) {
            return new DefaultEvent();
        }
        return event;
    }
}
